<template>
	<view class="preview">
		<swiper circular :current="currentIndex" @change="swiperChange">
			<swiper-item v-for="(item, index) in classList" :key="item.id">
				<image v-if="readImgs.includes(index)" @click="maskChage" :src="item.pic" mode="aspectFill"></image>
			</swiper-item>
		</swiper>
		<view class="mask" v-if="maskState">
			<view class="goBack" @click="goBack" :style="{top: getStatusBarHeight()+'px'}">
				<uni-icons type="back" color="#fff" size="20"></uni-icons>
			</view>
			<view class="count">{{currentIndex + 1}} / {{classList.length}}</view>
			<view class="time">
				<uni-dateformat :date="new Date()" format="hh:mm"></uni-dateformat>
			</view>
			<view class="date">
				<uni-dateformat :date="new Date()" format="MM月dd日"></uni-dateformat>
			</view>
			<view class="footer">
				<view class="box" @click="clickInfo">
					<uni-icons type="info" size="23"></uni-icons>
					<view class="text">信息</view>
				</view>
				<view class="box">
					<uni-icons type="info" size="23"></uni-icons>
					<view class="text">分数</view>
				</view>
				<view class="box">
					<uni-icons type="info" size="23"></uni-icons>
					<view class="text">下载</view>
				</view>
			</view>
		</view>
		<uni-popup ref="infoPopup" type="bottom">
			<view class="infoPopup">
				<view class="popupHeader">
					<view></view>
					<view class="title">
						详细信息
					</view>
					<view class="close" @click="clickInfoClose">
						<uni-icons type="closeempty" size="18" color="#999"></uni-icons>
					</view>
				</view>
				<scroll-view scroll-y>
					<view class="content">
						<view class="row" v-for="item in 5">
							<view class="label">id:</view>
							<text selectable class="value">dasdfas</text>
						</view>
					</view>
				</scroll-view>
			</view>
		</uni-popup>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import { getStatusBarHeight } from '@/utils/system.js'
import { onReady, onLoad } from '@dcloudio/uni-app'

const classList = ref([]);
const currentId = ref(null);
const currentIndex = ref(0);
const readImgs = ref([]);

const storageClassList = uni.getStorageSync("storageClassList") || [];
classList.value = storageClassList;

onLoad((e)=>{
	currentId.value = e.id;
	currentIndex.value = classList.value.findIndex(item=>item.id == currentId.value);
	readImgsFun();
})

const swiperChange = (e) => {
	currentIndex.value = e.detail.current;
	readImgsFun();
}
function readImgsFun(){
	readImgs.value.push(
		currentIndex.value<=0 ? classList.value.length -1 : currentIndex.value -1,
		currentIndex.value,
		currentIndex.value>=classList.value.length-1 ? 0 : currentIndex.value + 1
	);
	readImgs.value = [...new Set(readImgs.value)];
}

const goBack = () => {
	uni.navigateBack();
}

const maskState = ref(true)
const maskChage = () => {
	maskState.value = !maskState.value
}
//关闭遮罩
const clickInfoClose = () => {
	infoPopup.value.close();
}
// 遮罩
const infoPopup = ref(null);
const clickInfo = () => {
	infoPopup.value.open();
}
</script>

<style lang="scss" scoped>
.preview{
	width: 100%;
	height: 100vh;
	position: relative;
	swiper{
		width: 100%;
		height: 100%;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.mask{
		&>view{
			position: absolute;
			left: 0;
			right: 0;
			margin: auto;
			width: fit-content;
			color: #fff;
		}
		.goBack{
			width: 38rpx;
			height: 38rpx;
			padding: 30rpx;
			background: rgba(0, 0, 0, .5);
			left: 30rpx;
			top: 0;
			margin-left: 0;
			border-radius: 100px;
			backdrop-filter: bulr(10rpx);
			border: 1px solid rgba(255, 255, 255, .3);
			display: flex;
			align-items: center;
			justify-content: center;
		}
		.count{
			top: 10vh;
			background-color: rgba(0, 0, 0, .3);
			font-size: 28rpx;
			border-radius: 40rpx;
			padding: 8rpx 28rpx;
			backdrop-fillter: blur(10rpx);
		}
		.time{
			font-size: 140rpx;
			top:calc(10vh + 80rpx);
			font-weight: 100;
			line-height: 1em;
			text-shadow: 0 4rpx rgba(0, 0, 0, .3);
		}
		.date{
			font-size: 34rpx;
			top:calc(10vh + 230rpx);
			text-shadow: 0 4rpx rgba(0, 0, 0, .3);
		}
		.footer{
			background: rgba(255, 255, 255, .8);
			bottom: 10vh;
			width: 65vw;
			height: 120rpx;
			border-radius: 120rpx;
			color: #000;
			display: flex;
			justify-content: space-around;
			align-items: center;
			box-shadow: 0 2rpx 0 rgba(0, 0, 0, .1);
			backdrop-filter: blur(20rpx);
			.box{
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				padding: 2rpx 16rpx;
				.text{
					font-size: 26rpx;
					color: $text-font-color-2;
				}
			}
		}
	}
	.infoPopup{
		background: #fff;
		padding: 30rpx;
		border-radius: 30rpx 30rpx 0 0;
		overflow: hidden;
		.popupHeader{
			display: flex;
			justify-content: space-between;
			align-items: center;
			.title{
				color: $text-font-color-2;
				font-size: 26rpx;
			}
			.close{
				padding: 6rpx;
			}
		}
		scroll-view{
			max-height: 60vh;
			.content{
				.row{
					display: flex;
					padding: 16rpx 0;
					font-size: 32rpx;
					line-height: 1.7em;
					.label{
						color: $text-font-color-3;
						width: 140rpx;
						text-align: right;
						font-size: 30rpx;
					}
					.value{
						flex:1;
						width: 0;
					}
				}
			}
		}
	}
}
</style>
